<template>
	<view class="page">
		<z-paging ref="paging" v-model="dataList" @query="queryList">
			<template #top>
				<u-navbar title="我的订单" safeAreaInsetTop fixed placeholder :isBack="false" :border-bottom="false"></u-navbar>
				<view style="padding: 24rpx;background: #fff;border-bottom: solid 1px #f2f2f2;">
					<u-tabs :list="tabList" :bar-style="{background: '#FC7404'}" bar-width="48"
						active-color="#FC7404" inactive-color="#999999"  :current="tabIndex" @change="changeTab"></u-tabs>
				</view>
			</template>
			
			<!-- 列表 -->
			<view style="background: #fff;">
				<view style="padding: 24rpx 32rpx 0 32rpx;margin-bottom: 20rpx;" v-for="(item, index) in dataList" :key="index">
					<view style="border-bottom: #f2f2f2 solid 1px;padding-bottom: 24rpx;">
						
						<view style="display: flex;align-items: center;justify-content: space-between;">
							<view style="color: #999;">
							<!-- {{item.order_sn}} -->
							202204130925640001
							</view>
							<!-- <view style="color: #ff9900;">
								{{index == 0?'待支付':index==1?'待报价':index==2?'待分配':index==3?'待服务':index==4?'已完成':'退款/售后'}}
							</view> -->
							<view style="color: #ff9900;">
								{{index == 0?'待支付':index==1?'待报价':index==2?'待分配':index==3?'待服务':index==4?'已完成':'退款/售后'}}
							</view>
						</view>
						<view style="margin-top: 16rpx;">
							<view style="display: flex;align-items: center;">
								<view style="width: 20rpx;height: 20rpx;background: #333;border-radius: 50%;"></view>
								<view style="flex: 1;margin-left: 20rpx;">
									<view style="font-weight: bold;font-size: 30rpx;">{{item.gigjobs_name || '家政保洁(此处为需求工种)'}}</view>
									<!-- <view style="color: #999;margin-top: 10rpx;">
										<text v-for="(it, ind) in item.masterData" :key="ind" 
										style="padding-right: 24rpx;font-size: 26rpx;">{{it.master_name}}</text>
									</view> -->
								</view>
							</view>
							<view style="margin-top: 16rpx;display: flex;align-items: center;">
								<view style="width: 20rpx;height: 20rpx;background: #0daff0;border-radius: 50%;"></view>
								<view style="flex: 1;margin-left: 20rpx;">
									<view style="font-weight: bold;font-size: 30rpx;
									width: 300px;
									overflow: hidden;
									text-overflow: ellipsis;
									white-space: nowrap;">{{item.location_detail || '贵阳市南明区花果园M区8栋2单元2楼平台商铺'}}</view>
									<view style="color: #999;font-size: 26rpx;margin-top: 10rpx;">
										<text>{{item.nickname || '陈先生'}}</text>
										<text style="padding-left: 24rpx;">{{item.mobile || '156****5412'}}</text>
									</view>
								</view>
							</view>
						</view>
						<view style="font-size: 28rpx;margin-top: 16rpx;display: flex;align-items: center;justify-content: space-between;">
							<view style="color: #ff9900;font-weight: bold;font-size: 32rpx;">￥{{item.total_price || '100.05'}}</view>
							<view style="display: flex;align-items: center;" class="button-group">
								<view class="hollowcss" @click="toggleTagSelect(item)">联系客户</view>
								<!-- <view style="color: #909399;border: 2rpx solid #909399;
								border-radius: 10rpx;padding: 16rpx 0rpx;width: 80px;
								text-align: center;margin-left: 24rpx;" @click="toggleTagSelect(item)">删除订单</view> -->
								<!-- <view style="color: #909399;border: 2rpx solid #909399;
								border-radius: 10rpx;padding: 16rpx 0rpx;width: 80px;
								text-align: center;margin-left: 24rpx;" @click="toggleTagSelect(item)">查看师傅</view> -->
								<!-- <view style="color: #909399;border: 2rpx solid #909399;
								border-radius: 10rpx;padding: 16rpx 0rpx;width: 80px;
								text-align: center;margin-left: 24rpx;" @click="toggleTagSelect(item)">退款</view> -->
								<view v-if="index == 0" style="color: #fff;border: 2rpx solid #ff9900;background: #ff9900;
								border-radius: 10rpx;padding: 16rpx 0rpx;width: 80px;
								text-align: center;margin-left: 24rpx;" @click="toggleTagSelect(item)">催付款</view>
								<view class="solidcss" v-if="index ==1 ||  (item.total_price == 0 && item.order_status == 0)" 
								@click="toggleTagSelect(item, 0)">去报价</view>
<!-- 								<view class="solidcss" v-if="item.order_status == 1" @click="setAmount(item)">设置尾款</view>
								<view class="solidcss" v-if="item.order_status == 1" @click="toggleTagSelect(item, 1)">确定接单</view> -->
								<view class="solidcss" v-if="index == 2 || item.order_status == 13" @click="toggleTagSelect(item, 13)">分配师傅</view>
								<view v-if="index == 4" class="solidcss"  @click="toggleTagSelect(item)">提醒评价</view>
								<view v-if="index == 5" class="solidcss"  @click="toggleTagSelect(item)">反馈平台</view>
							</view>
						</view>
						
					</view>
				</view>
			</view>
			
			<template #bottom>
				<view class="footer">
					<button class="confirm-btn" @click="confirmSelection" style="background: #1877f2;color: #fff;">确定</button>
				</view>
			</template>
		</z-paging>
		
		<u-toast ref="uToast" />
		
		<view style="height: 200rpx;"></view>
		
		<!-- <view style="position: fixed;right: 32rpx;bottom: 204rpx;" @click="jumpTo('/pages/prescription/ordinaryEdit')">
			<image src="@/static/img/add.png" mode="widthFix" style="width: 80rpx;"></image>
		</view> -->
		<!-- 更多操作 -->
		<u-action-sheet :list="moreList" v-model="moreShow" border-radius="32"
		@click="moreClick"></u-action-sheet>
		
		<!-- 服务报价 -->
		<u-popup v-model="quotationShow" mode="bottom" border-radius="16" :mask-close-able="false">
			<view style="border-radius: 24rpx;background: #fff;padding: 24rpx;">
				<view style="margin-top: 12rpx;">
					<view class="cu-bar bg-white">
						<view style="text-align: center;font-weight: bold;font-size: 30rpx;">
							服务报价
						</view>
					</view>
					<view>
						<view style="padding:  32rpx;">
							<view style="padding: 24rpx;background: #fff;border-radius: 24rpx;font-size: 28rpx;color: #333A47;">
								<view style="padding-bottom: 16rpx;width: 120rpx;">报价金额</view>
								<view style="padding: 24rpx;background-color: #f6f6f6;border-radius: 12rpx;">
									<input type="digit" placeholder="输入服务报价金额" v-model="quotation">
								</view>
								<view style="color: #ff9900;font-size: 24rpx;margin-top: 16rpx;">* 请仔细评估后再进行合理填写</view>
							</view>
						</view>
					</view>
					<view style="height: 8rpx;width: 100%;background: #F5F8FF;"></view>
					<view style="display: flex;align-items: center;">
						<view style="padding: 32rpx 0;text-align: center;color: #333A47;font-size: 32rpx;width: 50%;"
						@click="quotationShow = false"> 取消 </view>
						<view style="padding: 48rpx 32rpx;text-align: center;color: #0daff0;font-size: 32rpx;flex: 1;">
							<view style="font-weight: bold;" @click="quotationConfirm">确认</view>
						</view>
					</view>
				</view>
			</view>
		</u-popup>
		
		<!-- 服务报价 -->
		<u-modal v-model="quotationShow1" title="服务报价" :show-cancel-button="true" confirm-text="确认" confirm-color="#0daff0"
		:title-style="{fontWeight: 'bold'}" @confirm="quotationConfirm" :async-close="true">
			<view class="slot-content">
				<view style="padding:  32rpx;">
					<view style="padding: 24rpx;background: #fff;border-radius: 24rpx;font-size: 28rpx;color: #333A47;">
						<view style="padding-bottom: 16rpx;width: 120rpx;">报价金额</view>
						<view style="padding: 24rpx;background-color: #f6f6f6;">
							<input type="text" placeholder="输入服务报价金额" v-model="quotation">
						</view>
						<view style="color: #ff9900;font-size: 24rpx;margin-top: 16rpx;">* 请仔细评估后再进行合理填写</view>
					</view>
				</view>
			</view>
		</u-modal>
		
		<!-- 设置尾款 -->
		<u-popup v-model="amountShow" mode="bottom" border-radius="16" :mask-close-able="false">
			<view style="border-radius: 24rpx;background: #fff;padding: 24rpx;">
				<view style="margin-top: 12rpx;">
					<view class="cu-bar bg-white">
						<view style="text-align: center;font-weight: bold;font-size: 30rpx;">
							设置尾款
						</view>
					</view>
					<view>
						<view style="padding:  32rpx;">
							<view style="padding: 24rpx;background: #fff;border-radius: 24rpx;font-size: 28rpx;color: #333A47;">
								<view style="padding-bottom: 16rpx;width: 120rpx;">尾款</view>
								<view style="padding: 24rpx;background-color: #f6f6f6;border-radius: 12rpx;">
									<input type="digit" placeholder="输入服务尾款金额" v-model="amount">
								</view>
								<view style="color: #ff9900;font-size: 24rpx;margin-top: 16rpx;">* 请仔细评估后再进行合理填写</view>
							</view>
						</view>
					</view>
					<view style="height: 8rpx;width: 100%;background: #F5F8FF;"></view>
					<view style="display: flex;align-items: center;">
						<view style="padding: 32rpx 0;text-align: center;color: #333A47;font-size: 32rpx;width: 50%;"
						@click="amountShow = false"> 取消 </view>
						<view style="padding: 48rpx 32rpx;text-align: center;color: #0daff0;font-size: 32rpx;flex: 1;">
							<view style="font-weight: bold;" @click="amountConfirm">确认</view>
						</view>
					</view>
				</view>
			</view>
		</u-popup>
		
		<!-- 删除弹窗 -->
		<u-modal v-model="delShow" title="确定删除" :show-cancel-button="true" confirm-text="确认删除"
		:title-style="{fontWeight: 'bold'}" @confirm="lvDelYes">
			<view class="slot-content">
				<view style="padding: 48rpx 32rpx 64rpx 32rpx;">
					<view style="font-size: 28rpx;color: #101010;text-align: center;">是否确定删除改等级？删除后不可恢复</view>
				</view>
			</view>
		</u-modal>
		
		<u-tabbar v-model="current" :list="tabbar" active-color="#0daff0"></u-tabbar>
	</view>
</template>

<script>
	import { getTabbarConfig } from '@/common/tabbar';
	import { request } from 'utils/request.js';
	export default {
		data() {
			return {
				current: 1,
				tabbar: getTabbarConfig(true),
				
				operate_id: 0,
				quotationShow: false,
				quotation: '',
				
				dataList: [],
				keyword:'',
				
				tabIndex: 0,
				tabList:[{
						name: '待支付',
						filter: 'deposit'
					},{
						name: '待报价',
						filter: 'deposit'
					},{
						name: '待分配',
						filter: 'deposit'
					},{
						name: '待服务',
						filter: 'deposit'
					},{
						name: '已完成',
						filter: 'deposit'
					}],
				// tabList: [{
				// 		name: '全部',
				// 		filter: 'all'
				// 	},
				// 	{
				// 		name: '定金待付',
				// 		filter: 'deposit'
				// 	},
				// 	{
				// 		name: '等待接单',
				// 		filter: 'isnotb'
				// 	},
				// 	{
				// 		name: '等待派单',
				// 		filter: 'amount'
				// 	},
				// 	// {name: '等待派单', filter: 'isnotm'},
				// 	{
				// 		name: '等待上门',
				// 		filter: 'service'
				// 	},
				// 	{
				// 		name: '已完成',
				// 		filter: 'completed'
				// 	},
				// 	{
				// 		name: '维权',
				// 		filter: 'maintanance'
				// 	},
				// ],
				serviceItemsSum: 0,
				
				// 示例数据
				listData: [],
				selectedIndexes: [] ,// 存储被选中的索引
				selectedTags: [],
				
				
				amountShow: false,
				amount: '',
				
				delShow:false,
				moreShow:false,
				moreList:[],
				quotationShow1:false,
				
			};
		},
		onLoad(options) {
		    // 从父页面传递的已选标签
		    if (options.selected) {
				this.selectedTags = JSON.parse(options.selected);
		    }
		    // this.filteredTags = [...this.allTags];
			// this.loadSelectedTags();
			uni.$on('htmlRefresh', (e) => {
				this.$refs.paging.reload()//重置
				return;
				let selectedTagsJson = e.selectedTagsJson;
				// console.log('子页面---->>>>>>', selectedTagsJson);
				if(selectedTagsJson) {
					// this.selectedTags = JSON.parse(selectedTagsJson);
					// console.log('selectedTags: ', this.selectedTags)
					// this.serviceItemsSum = this.selectedTags.length;
				}
			});
		},
		methods: {
			// 选择服务项目
			navigateToTagSelect() {
			    // 跳转到标签选择页面，并传递当前已选标签
			    uni.navigateTo({
					url: '/pages/merchant/serviceItems?selected=' + JSON.stringify(this.selectedTags)
				});
			},
			changeTab(index) {
				console.log('tabIndex： ', index)
				this.tabIndex = index;
				// uni.$emit('refreshOrder', this.tabList[this.tabIndex].filter);
			},
			// 搜索标签
			onSearch() {
				this.$refs.paging.reload()//重置
			},
			// 切换标签选择状态
			toggleTagSelect(item, status) {
				console.log('item: ', item);
				console.log('status: ', status);
				this.operate_id = item.id
				if(status == 0){// 去报价
					this.quotationShow = true;
				}
				if(status == 1){// 直接接单
					// this.quotationShow = true;
					uni.navigateTo({
						url: '/pages/master/lis?order_id=' + item.id
					})
				}
				if(status == 13){// 分配师傅
					uni.navigateTo({
						url: '/pages/master/lis?order_id=' + item.id
					})
				}
			},
			// 设置尾款
			setAmount(item){
				this.operate_id = item.id
				this.amountShow = true;
			},
			amountConfirm(){
				console.log(this.operate_id);
				console.log('amount: ', this.amount);
				if(this.amount == ''){
					uni.showToast({
						title: '服务尾款金额不能为空',
						duration: 2000,
						icon: 'none'
					});
					return;
				}
				request.getWithToken({
					url: '/order/orderAmount',
					data: {operate_id: this.operate_id, amount: this.amount}
				}).then(res=>{
					console.log(res)
					uni.showToast({
						title: res.msg,
						duration: 2000,
						icon: 'none'
					});
					if(res.code == 1){
						this.$refs.paging.reload()//重置
						this.amountShow = false;
					}
				})
			},
			quotationConfirm(){
				console.log('quotation: ', this.quotation);
				if(this.quotation == ''){
					uni.showToast({
						title: '报价金额不能为空',
						duration: 2000,
						icon: 'none'
					});
					return;
				}
				request.getWithToken({
					url: '/order/orderQuotation',
					data: {operate_id: this.operate_id, quotation: this.quotation}
				}).then(res=>{
					console.log(res)
					uni.showToast({
						title: res.msg,
						duration: 2000,
						icon: 'none'
					});
					if(res.code == 1){
						this.$refs.paging.reload()//重置
						this.quotationShow = false;
					}
				})
			},
			// 确认选择
			confirmSelection() {
				// 保存到本地存储
				// uni.setStorageSync('selectedTags', JSON.stringify(this.selectedTags));
				let selectedTagsJson = JSON.stringify(this.selectedTags);
				// 返回上一页
				setTimeout(() => {
					uni.navigateBack();
					uni.$emit('htmlRefresh', {selectedTagsJson: selectedTagsJson});
				}, 600);
				// uni.navigateBack();
			},
			moreClick(e){
				console.log(e)
			},
			// 获取列表
			queryList(pageNo, pageSize) {
				
				setTimeout(res=>{
					this.$refs.paging.complete([{index:0},{index:1},{index:2},{index:3},{index:4},{index:5}])
					
				},1000)
				return
				
				let params = {};
				params.page = pageNo;
				params.keyword = this.keyword;
				request.getWithToken({
					url: '/order/orderLis',
					data: params
				}).then(res=>{
					// console.log(res)
					// this.$refs.paging.complete(res.data.dataList);
					this.$refs.paging.complete([{index:0},{index:1},{index:2},{index:3},{index:4},{index:5}])
					// this.filteredTags = [...res.data];
					// this.$refs.paging.complete(this.filteredTags);
				})
			},
			followClick(e){
				let talkData = uni.getStorageSync('talkData');
				
			},
			jumpTo(path){
				uni.navigateTo({
					url: path
				})
			},
			onSubmitSave(){
				uni.navigateTo({
					url: '/pages/prescription/selectMedicine'
				})
			}
		}
	}
</script>

<style>
	page{
		background-color: #f2f2f2 !important;
	}
</style>
<style lang="scss" scoped>
	.button-group {
		margin: 10rpx 0;
		display: flex;
		justify-content: flex-end;
		margin-top: 30rpx;
	
		.item-btn {
			align-self: center;
			display: flex;
			justify-content: center;
			align-items: center;
			margin: 0;
			padding: 0 20rpx;
			height: 56rpx;
			border: 1px solid #888;
			border-radius: 10rpx;
			color: #888;
			font-size: 26rpx;
	
			&+.item-btn {
				margin-left: 22rpx;
			}
	
			&.primary {
				color: #FFF;
				border: 1px solid #fb7601;
				background-color: #fb7601;
			}
		}
	}
	
	.solidcss{
		color: #fff;border: 2rpx solid #0daff0;background: #0daff0;
		border-radius: 10rpx;padding: 16rpx 0rpx;width: 80px;
		text-align: center;margin-left: 24rpx;
	}
	.hollowcss{
		color: #909399;border: 2rpx solid #909399;
		border-radius: 10rpx;padding: 16rpx 0rpx;width: 80px;
		text-align: center;margin-left: 24rpx;
	}
</style>
